#作者：二门
import json
import datetime
from flask import Flask, request
from .Connect_Mysql import Connect_Mysql
from . import app_login

class DateEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')

        elif isinstance(obj, datetime.date):
            return obj.strftime("%Y-%m-%d")

        else:
            return json.JSONEncoder.default(self, obj)


@app_login.route('/login', methods = ['GET', 'POST'])

def login():

    if request.method == 'POST':

        conn_obj = Connect_Mysql()

        phone = request.form.get('phone')

        pass_word = request.form.get('pass_word')

        # print(phone,pass_word)

        if phone and pass_word:

            result_info = conn_obj.login(phone,pass_word)

            conn_obj.close()

            return result_info

        else:
            
            return {
                    'status': -1,
                    'errorCode': '7',
                    'errorMsg':'缺少信息',
                    'resultBody':None
                }

    else:
            
        return {
                    'status': -1,
                    'errorCode': '5',
                    'errorMsg':'请求方式错误',
                    'resultBody':None
                }





if __name__ == "__main__":
    
    app.run(debug = True)